<!-- 首页 -->
<template>
	<view class="index flex flex-dir-c">
		<view class="index_nav" :style="{
			paddingTop: $u.addUnit($u.getPx('44px') + $u.sys().statusBarHeight,'px')
		}">
			<u-navbar :left-icon="false">
				<view class="flex flex-ai-c title" @click="devicePopupShow = true" slot="left">
					<text>{{deviceInfo.device_name}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</u-navbar>
			<view class="text">距离您{{deviceInfo.distanceText}}</view>
			<view class="address flex flex-jc-sb flex-ai-c">
				<view class="address-top s-line-text">
					<view style="margin-right: 10rpx;display: inline-block;vertical-align: middle;">
						<i-icon icon="dingwei2" />
					</view>
					<text>{{deviceInfo.addr}}</text>
				</view>
				<view class="flex flex-ai-c address-more" style="margin-left: 10rpx;white-space: nowrap;">
					<text>更多</text>
					<u-icon name="arrow-right" size="18" color="#999999"></u-icon>
				</view>
			</view>
		</view>
		
		
		<!-- 占位 -->
		<!-- <view class="" :style="{marginTop:placeholder*2 + 'rpx'}"></view> -->
		
		<view class="index_tabs">
			<u-tabs padding="0 25px" keyName="c_name" ref="uTabs" lineColor="#333333" :list="tabsData" activeStyle="color:#333333"
				inactiveStyle="color: #666666" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</view>
		<swiper class="swiper" :current="current" @change="swiperChange">
			<swiper-item class="swiper-item" v-for="(item, index) in tabsData" :key="index">
				<scroll-view scroll-y style="height: 100%;">
					<view class="index_content flex flex-wrap-w" v-if="tabsData[current] && tabsData[current].goods_list && tabsData[current].goods_list.length">
						<view v-for="(res,index) in tabsData[current].goods_list" :key="res.id"
							class="flex flex-dir-c flex-ai-c list">
							<view class="index-content-img">
								<image :src="res.goods_main_image"></image>
								
								<view v-if="!res.stock" style="width: 300rpx;height: 326rpx;position: absolute;top: 0;right: 0;text-align: center;line-height: 326rpx;background: #000000;opacity: 0.5;">
									<text style="opacity: 1;color: #fff;font-size: 36rpx;font-weight: 600;">缺 货</text>
								</view>
							</view>
							<view class="index-content-text description" style="text-align: center;">{{res.goods_title}}</view>
							<view class="index-content-btn">
								<view class="flex flex-ai-c flex-jc-c">¥ {{res.sales_price}}</view>
								<view class="flex flex-ai-c flex-jc-c">购买</view>
							</view>
						</view>
					</view>
					<view class="flex flex-jc-c flex-ai-c" v-else style="height: 100%;">
						<u-empty text="数据为空" mode="list"></u-empty>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		<device-popup :isAll="false" @changeAddress="changeAddress" @close="devicePopupShow = false" :show="devicePopupShow"/>
		<TabBar :current-page="-1" />
	</view>
</template>

<script>
	import home from '@/api/home.js'
	import devicePopup from '@/components/devicePopup.vue';
	export default {
		components: {devicePopup},
		data() {
			return {
				devicePopupShow: false,
				tabsData: [],
				current: 0,
				userinfo: uni.getStorageSync('userinfo'),
				deviceInfo: {},
				device_no: '',
				lat: '',
				lng: ''
			}
		},
		onLoad(op) {
			this.device_no = op.device_no
			if(op.lat) {
				this.lng = op.lng
				this.lat = op.lat
			}
			this.getGoodsListByEquipmentNo(op.lat, op.lng)
		},
		methods: {
			changeAddress(device_no,current,name) {
				this.tabsData = []
				this.deviceInfo = []
				this.devicePopupShow = false
				this.device_no = device_no
				this.getGoodsListByEquipmentNo(this.lat, this.lng)
			},
			async getGoodsListByEquipmentNo(lat, lng) {
				let addr = uni.getStorageSync('address')
				lat = lat ? lat : addr.lat
				lng = lng ? lng : addr.lng
				const res = await home.getGoodsListByEquipmentNo({
					device_no: this.device_no,
					lat: lat,
					lng: lng
				})
				this.loading = true
				this.tabsData = res.data.goods_info
				this.deviceInfo = res.data.device_info
			},

			swiperChange({
				detail: {
					current
				}
			}) {
				this.current = current
			},
			change({
				index
			}) {
				this.current = index
			}
		},
		options: {
			styleIsolation: 'shared'
		},
	}
</script>
<style>
	page {
		background: #fff;
		height: 100%;
	}
</style>
<style scoped lang="scss">
	/deep/.u-tabs__wrapper__nav__item:first-child{
		padding-left: 0 !important;
	}
	/deep/.u-tabs__wrapper__nav__item:last-child{
		padding-right: 0 !important;
	}
	.description {
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	
	/deep/.u-navbar__content__left{
		padding-left: 0 !important;
	}
	.index {
		height: 100%;

		&_nav {
			box-sizing: border-box;
			padding-left: 40rpx;
			background-color: #fff;
			padding-top: 70rpx;
			padding-right: 30rpx;
			.title {
					padding-left: 40rpx;
				&>text {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #000000;
				}

			}

			.text {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
				margin-bottom: 25rpx;
			}

			.address {

				.address-top {
					text {
						font-size: 28rpx;
						font-weight: 400;
						color: #999999;
					}
				}

				.address-more {
					text {
						font-size: 24rpx;
						font-weight: 400;
						color: #999999;
					}

					image {
						width: 12rpx;
						height: 20rpx;
					}
				}
			}
		}


		.index_tabs {
			margin: 46rpx 100rpx 36rpx 100rpx;
		}

		.index_content {
			padding: 0 20rpx;

			.list {
				width: 50%;
				
				.index-content-img {
					position: relative;
					image {
						width: 300rpx;
						height: 326rpx;
					}
				}


				.index-content-text {
					font-size: 24rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 600;
					color: #333333;
					margin: 40rpx 0rpx 30rpx 0rpx;
					width: 100%;
					padding: 0 20rpx;
					height: 80rpx;
				}

				.index-content-btn {
					width: 300rpx;
					height: 60rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 2rpx 10rpx 0rpx rgba(0, 0, 0, 0.1);
					border-radius: 30rpx;
					display: flex;
					margin-bottom: 62rpx;

					&>view {
						width: 50%;
						height: 100%;
					}

					&>view:nth-child(1) {
						background-color: #fff;
						border-radius: 100rpx 0rpx 0rpx 100rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 600;
						color: #333333;
					}

					&>view:nth-child(2) {
						background: #FFBA2F;
						border-radius: 0rpx 100rpx 100rpx 0rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 600;
						color: #000000;
					}
				}
			}
		}
	}
</style>